home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / python2.4 / test / test_imp.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2005-10-18  |  1KB  |  48 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.4)
  3.  
  4. import imp
  5. from test.test_support import TestFailed, TestSkipped
  6.  
  7. try:
  8.     import thread
  9. except ImportError:
  10.     raise TestSkipped('test only valid when thread support is available')
  11.  
  12.  
  13. def verify_lock_state(expected):
  14.     if imp.lock_held() != expected:
  15.         raise TestFailed('expected imp.lock_held() to be %r' % expected)
  16.     
  17.  
  18.  
  19. def testLock():
  20.     LOOPS = 50
  21.     lock_held_at_start = imp.lock_held()
  22.     verify_lock_state(lock_held_at_start)
  23.     for i in range(LOOPS):
  24.         imp.acquire_lock()
  25.         verify_lock_state(True)
  26.     
  27.     for i in range(LOOPS):
  28.         imp.release_lock()
  29.     
  30.     verify_lock_state(lock_held_at_start)
  31.     if not lock_held_at_start:
  32.         
  33.         try:
  34.             imp.release_lock()
  35.         except RuntimeError:
  36.             pass
  37.  
  38.         raise TestFailed('release_lock() without lock should raise RuntimeError')
  39.     
  40.  
  41.  
  42. def test_main():
  43.     testLock()
  44.  
  45. if __name__ == '__main__':
  46.     test_main()
  47.  
  48.